$(function(){
	initPage();
	//初始化代码编辑器edit-area
	editAreaLoader.init({
		id: "code-edit-area"	
		,start_highlight: true
		,allow_toggle: false
		,word_wrap: true
		,language: "zh"
		,syntax: "java"	
		,toolbar: " undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, fullscreen"
		,syntax_selection_allow: "c,css,html,java,javascript,php,python,ruby,sql,xml"
		,show_line_colors: true
		,is_editable:true
	});
	//提交后刷新显示图片。
	var filepath = $("#lookPhotoFilePath").val();
	if(filepath.length > 0){
		//有图片
		$("<img/>").attr("src","/utils/loadImg?lookPhotoPath=" + filepath).css({
    		"width":"100px",
    		"height":"100px"
    	}).appendTo($("#img-area").text(""));
	}
	//反馈的codeType需要js控制页面显示到select中
	var codeType = $("#codeType").val();
	if(codeType.length > 0){
		//显示到select中option
		$("#codeTypeSelect option[value="+codeType+"]").attr("selected",true);
	}
	//添加刷新按钮
	$("#refersh-img").click(function(){
		var path = $("#lookPhotoFilePath").val();
		$("#img-area img").attr("src","/utils/loadImg?lookPhotoPath=" + path +"&rand=" + Math.random());
	});
	
	$("#btn_look_photo").click(function(){
		 $.ajaxFileUpload({  
            url:'/ulp.servlet',  
            secureuri:false,  
            fileElementId:'look_photo_input',//file标签的id  
            dataType: 'content',//返回数据的类型  
            data:{"lookPhotoType":$("#look_photo-type").val()},
            success: function (data,status) {  
            	//console.info(data);
            	if(data.flag == "0"){
            		$("<img/>").attr("src","/utils/loadImg?lookPhotoPath=" + data.filepath).css({
                		"width":"100px",
                		"height":"100px"
                	}).appendTo($("#img-area").text(""));
            		$("#lookPhotoFilePath").val(data.filepath);
            	}else if(data.flag == "1"){
            		$("#look_photo_res").text("未选择上传文件");
            	}else if(data.flag == "2"){
            		$("#look_photo_res").text("缩览图文件类型不被支持");
            	}else if(data.flag == "3"){
            		$("#look_photo_res").text("缩览图文件大小超出支持")
            	}
            },
            error: function (data, status, e)//服务器响应失败处理函数
            {
                alert("error:"+e);
            }
        });  
	});
});
